package com.mrjy.video.controller;
import com.mrjy.common.entity.UserInfo;
import com.mrjy.common.entity.VideoCommentInfo;
import com.mrjy.common.util.GlobalConstant;
import com.mrjy.video.bo.IVideoCommentInfoBo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
/**
 * 微课评论控制类
 * @author Javin
 */
@Controller
@RequestMapping("/video/videoCommentInfo")
public class VideoCommentInfoController {
    @Resource
    private IVideoCommentInfoBo videoCommentInfoBo;
    /**
     * 添加课程后台
     * @param videoCommentInfo
     * @return
     */
    @RequestMapping("/addVideoCommentInfo")
    @ResponseBody
    public Object addVideoCommentInfo(VideoCommentInfo videoCommentInfo, HttpSession session) {
        UserInfo userInfo = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
        Map<String, Object> map = new HashMap<String, Object>();
        if(userInfo == null){
            map.put("err_code", -1);
            map.put("err_msg","用户信息不存在");
            return map;
        }
        videoCommentInfo.setUserId(userInfo.getId());
        return videoCommentInfoBo.txAddVideoCommentInfo(videoCommentInfo,map);
    }
    /**
     * 视频添加评论和回复内容
     *
     */
    @RequestMapping("/toCommentForPhone")
    @ResponseBody
    public Object toComment(VideoCommentInfo vComment, HttpSession session) {
        return videoCommentInfoBo.txtoComment(vComment, session);
    }

    /**
     * 加载后台课程列表
     *
     * @param videoCommentInfo
     * @return
     */
    @RequestMapping("/videoCommentInfoList")
    @ResponseBody
    public Object videoCommentInfoList(VideoCommentInfo videoCommentInfo, HttpSession session) {
        return videoCommentInfoBo.videoCommentInfoList(videoCommentInfo);
    }

    /**
     * 根据ID查询课程
     *
     * @return
     */
    @RequestMapping("/queryById")
    @ResponseBody
    public Object queryById(int id) {
        VideoCommentInfo video = videoCommentInfoBo.queryById(id);
        return video;
    }

    /**
     * 修改
     *
     * @param videoCommentInfo
     * @return
     */
    @RequestMapping("/updateById")
    @ResponseBody
    public Object updateById(VideoCommentInfo videoCommentInfo) {
        // Activity.setId(2);
        // Activity.setPassword(MD5Encrypt.encryptByMD5("123abc"));
        videoCommentInfoBo.txUpdateById(videoCommentInfo);
        return "ok";
    }

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    @RequestMapping("/deleteByIds")
    @ResponseBody
    public Object deleteByIds(int[] ids) {
        return videoCommentInfoBo.txDeleteByIds(ids);
    }

    /**
     * 禁用、起用
     *
     * @param ids
     * @return
     */
    @RequestMapping("/updateDisableFlag")
    @ResponseBody
    public Object updateDisableFlag(VideoCommentInfo videoCommentInfo) {
        return videoCommentInfoBo.updateDisableFlag(videoCommentInfo);
    }

    /**
     * 根据ID查询课程
     *
     * @return
     */
    @RequestMapping("/queryByVideoId")
    @ResponseBody
    public Object queryByVideoId(int videoId) {
        return videoCommentInfoBo.queryByVideoId(videoId);
    }

    /**
     * 根据ID查询课程
     *
     * @return
     */
    @RequestMapping("/queryPageByVideoId")
    @ResponseBody
    public Object queryPageByVideoId(VideoCommentInfo comment) {
        return videoCommentInfoBo.queryPageByVideoId(comment);
    }


    /**
     * 根据视频id查询分页评论列表
     * @param comment
     * @author Javin: inUer = true,isNew = true
     */
    @RequestMapping("/queryPageCommentsByVideoId")
    @ResponseBody
    public Object queryPageCommentsByVideoId(VideoCommentInfo comment, HttpSession session) {
        return videoCommentInfoBo.queryPageCommentsByVideoId(comment, session);
    }


    @RequestMapping("/export")
    @ResponseBody
    public Object export(VideoCommentInfo comment, HttpSession session, HttpServletResponse response) {
        return videoCommentInfoBo.export(comment, session, response);
    }


    /**
     * 查询出 显示全站最新的微课学习笔记【微课留言】及来源微课名称
     *
     * @param comment
     * @param videoComment
     * @author Javin: inUer = true,isNew = true
     */
    @RequestMapping("/queryVideoComments")
    @ResponseBody
    public Object queryVideoComments(VideoCommentInfo videoComment) {
        return videoCommentInfoBo.queryVideoComments(videoComment);
    }
}
